#include <iostream>
#include <cstring>
#include <queue>
#include <map>
#include <vector>
#include <string.h>
using namespace std;

int n;
int mp[1010][1010];
int dp[1010][1010];

int main()
{
    int ans = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= i; j++)
        {
            cin >> mp[i][j];
        }
    }
    dp[1][1] = mp[1][1];
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= i; j++)
        {
            dp[i][j] = max(dp[i - 1][j] + mp[i][j], dp[i - 1][j - 1] + mp[i][j]);
        }
    }
    for (int i = 1; i <= n; i++)
    {
        ans = max(dp[n][i], ans);
    }
    cout << ans << endl;
    system("pause");
    return 0;
}
